//
//  SalesAssistantApp.swift
//  SalesAssistant
//
//  Created by 1 on 2024/3/6.
//

import SwiftUI

@main
struct SalesAssistantApp: App {
    
    @AppStorage("userAgreePrivacyPolicy") var userAgreePrivacyPolicy: Bool = false
    
    init() {
//        UserDefaults.standard.set(false, forKey: testEnvironment)
        setupAppearance()
    }
    
    var body: some Scene {
        WindowGroup {
            if(userAgreePrivacyPolicy){
                ContentView()
                    .navigationViewStyle(.stack)
                    .onAppear(){
                        setupAppearance()
                    }
            }else{
                PrivacyPolicyPage()
                    .navigationViewStyle(.stack)
            }
        }
    }
    
    func setupAppearance() {
        // 设置底部tab
        let appearance = UITabBarAppearance()
        if(MBAInfo.isVestP()){
            appearance.backgroundColor = MBAColor.com_textBg.uicolor
            appearance.shadowImage = UIImage()
            appearance.shadowColor = .clear
        }else{
            appearance.backgroundColor = MBAColor.com_background.uicolor
        }
        UITabBar.appearance().scrollEdgeAppearance = appearance
        UITabBar.appearance().standardAppearance = appearance

        // 设置导航栏颜色
        let navibarAppearance = UINavigationBar.appearance()
        let navibarAppearance1 = UINavigationBarAppearance()
        navibarAppearance1.shadowImage = UIImage()
        navibarAppearance1.shadowColor = .clear
//        navibarAppearance1.configureWithOpaqueBackground()//这行会导致下划线一直出现
        navibarAppearance1.backgroundColor = MBAColor.com_background.uicolor
        navibarAppearance.standardAppearance = navibarAppearance1
        navibarAppearance.scrollEdgeAppearance = navibarAppearance1
        navibarAppearance.tintColor = MBAColor.com_background.uicolor
        navibarAppearance.barTintColor = MBAColor.com_background.uicolor
        navibarAppearance.shadowImage = UIImage()
        navibarAppearance.backgroundColor = MBAColor.com_background.uicolor
        navibarAppearance.setBackgroundImage(UIImage(), for: .default)
        return
    }
}
